package hiho.ku._1034;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.TreeMap;

class Treap {

	class TreapNode {

		private static final int BIGNUMBER = 5000000;

		// 统计用
		private int size;
		private int sum;

		private int value;
		private int count;
		private int mark;
		private TreapNode leftKid;
		private TreapNode rightKid;

		private TreapNode(int value) {
			this.value = value;
			this.count = 1;
			this.mark = new Random().nextInt(BIGNUMBER);
			this.leftKid = null;
			this.rightKid = null;

			this.size = 1;
			this.sum = this.value;
		}

		private void recount() {
			int _size = this.count;
			_size += (this.leftKid != null) ? this.leftKid.size : 0;
			_size += (this.rightKid != null) ? this.rightKid.size : 0;
			this.size = _size;

			int _sum = this.value * this.count;
			_sum += (this.leftKid != null) ? this.leftKid.sum : 0;
			_sum += (this.rightKid != null) ? this.rightKid.sum : 0;
			this.sum = _sum;
		}

		private void swapValuesWith(TreapNode other) {
			int tmp = this.value;
			this.value = other.value;
			other.value = tmp;
			tmp = this.count;
			this.count = other.count;
			other.count = tmp;
			tmp = this.mark;
			this.mark = other.mark;
			other.mark = tmp;
		}

		private void rotateLeft() {
			this.swapValuesWith(this.rightKid);
			TreapNode _n = this.rightKid.rightKid;
			this.rightKid.rightKid = this.rightKid.leftKid;
			this.rightKid.leftKid = this.leftKid;
			this.leftKid = this.rightKid;
			this.rightKid = _n;

			this.leftKid.recount();
			this.recount();
		}

		private void rotateRight() {
			this.swapValuesWith(this.leftKid);
			TreapNode _n = this.leftKid.leftKid;
			this.leftKid.leftKid = this.leftKid.rightKid;
			this.leftKid.rightKid = this.rightKid;
			this.rightKid = this.leftKid;
			this.leftKid = _n;

			this.rightKid.recount();
			this.recount();
		}

		private void balance() {
			if (this.leftKid != null) {
				if (this.rightKid == null
						|| this.leftKid.mark > this.rightKid.mark) {
					if (this.leftKid.mark > this.mark)
						this.rotateRight();
				} else if (this.rightKid != null) {
					if (this.rightKid.mark > this.mark)
						this.rotateLeft();
				}
			} else if (this.rightKid != null) {
				if (this.rightKid.mark > this.mark)
					this.rotateLeft();
			}
		}

		public void insert(int value) {
			if (value == this.value)
				this.count++;
			else if (value < this.value) {
				if (this.leftKid == null)
					this.leftKid = new TreapNode(value);
				else
					this.leftKid.insert(value);
			} else {
				if (this.rightKid == null)
					this.rightKid = new TreapNode(value);
				else
					this.rightKid.insert(value);
			}
			this.recount();
			this.balance();
		}

		/*
		 * IMPORTANT: 首先将当前节点标记设为-1
		 */
		private void delete(TreapNode parent, boolean isLeft) {
			if (this.leftKid == null && this.rightKid == null) {
				if (isLeft)
					parent.leftKid = null;
				else
					parent.rightKid = null;
				return;
			}
			this.balance();
			if (this.leftKid != null && this.leftKid.mark == -1)
				this.leftKid.delete(this, true);
			else
				this.rightKid.delete(this, false);
			this.recount();
		}

		private void delete(TreapNode parent, boolean isLeft, int value) {
			if (value == this.value) {
				this.count--;
				if (this.count <= 0) {
					this.mark = -1;
					this.delete(parent, isLeft);
				}
			} else {
				if (value < this.value && this.leftKid != null)
					this.leftKid.delete(this, true, value);
				else if (value > this.value && this.rightKid != null)
					this.rightKid.delete(this, false, value);
			}
			this.recount();
		}

		public int sumLessThan(int value) {
			if (value == this.value)
				return (this.leftKid != null) ? this.leftKid.sum : 0;
			else if (value < this.value)
				return (this.leftKid != null) ? this.leftKid.sumLessThan(value)
						: 0;
			else
				return ((this.leftKid != null) ? this.leftKid.sum : 0)
						+ this.count
						* this.value
						+ ((this.rightKid != null) ? this.rightKid
								.sumLessThan(value) : 0);
		}

		public int countMoreThan(int value) {
			if (value == this.value)
				return (this.rightKid != null) ? this.rightKid.size : 0;
			else if (value > this.value)
				return (this.rightKid != null) ? this.rightKid
						.countMoreThan(value) : 0;
			else
				return ((this.rightKid != null) ? this.rightKid.size : 0)
						+ this.count
						+ ((this.rightKid != null) ? this.rightKid
								.countMoreThan(value) : 0);
		}

	}

	// 根节点值为0，mark巨大
	private final TreapNode root;

	public Treap() {
		root = new TreapNode(0);
		root.mark = TreapNode.BIGNUMBER;
	}

	public void insert(int value) {
		root.insert(value);
	}

	public void delete(int value) {
		if (root.rightKid != null)
			root.rightKid.delete(root, false, value);
	}

	public int sumLessThan(int value) {
		return root.sumLessThan(value);
	}
	
	public int countMoreThan(int value) {
		return root.countMoreThan(value) - ((value < 0)? 1 : 0);
	}

}

public class Main {
	
	private static class Area {
		int left;
		int right;
		public Area(int left, int right) {
			super();
			this.left = left;
			this.right = right;
		}
	}

	private static class Mark {
		boolean insert;
		int position;
		int time;
		public Mark(boolean insert, int position, int time) {
			super();
			this.insert = insert;
			this.position = position;
			this.time = time;
		}
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		BigInteger[] startPower = new BigInteger[n];
		BigInteger[] maxPower = new BigInteger[n];
		BigInteger[] rapid = new BigInteger[n];
		for (int i = 0; i < n; i++) {
			startPower[i] = in.nextBigInteger();
			maxPower[i] = in.nextBigInteger();
			rapid[i] = in.nextBigInteger();
		}
		
		Comparator<Area> areaComparator = new Comparator<Area>() {
			@Override
			public int compare(Area arg0, Area arg1) {
				return arg0.left - arg1.left;
			}
		};

		Area[] formatArea = new Area[0];
		Mark[] formatMark = new Mark[0];
		
		int m = in.nextInt();
		List<Mark> marksList = new ArrayList<Mark>();
		int t = in.nextInt();
		int l = in.nextInt();
		int r = in.nextInt();
		List<Area> areaList = new ArrayList<Area>();
		areaList.add(new Area(l, r));
		int lastT = t;
		for (int i = 1; i < m; i++) {
			t = in.nextInt();
			l = in.nextInt();
			r = in.nextInt();
			if (t == lastT)
				areaList.add(new Area(l, r));
			else {
				Area[] areas = areaList.toArray(formatArea);
				Arrays.sort(areas, areaComparator);
				int _l = areas[0].left;
				int _r = areas[0].right;
				for (int j = 1; j < areas.length; j++)
					if (areas[j].left > _r) {
						marksList.add(new Mark(true, _l - 1, lastT));
						marksList.add(new Mark(false, _r, lastT));
						_l = areas[j].left;
						_r = areas[j].right;
					} else
						_r = Math.max(_r, areas[j].right);
				marksList.add(new Mark(true, _l - 1, lastT));
				marksList.add(new Mark(false, _r, lastT));
				areaList.clear();
				areaList.add(new Area(l, r));
				lastT = t;
			}
		}
		Area[] areas = areaList.toArray(formatArea);
		Arrays.sort(areas, areaComparator);
		int _l = areas[0].left;
		int _r = areas[0].right;
		for (int j = 1; j < areas.length; j++)
			if (areas[j].left > _r) {
				marksList.add(new Mark(true, _l - 1, lastT));
				marksList.add(new Mark(false, _r, lastT));
				_l = areas[j].left;
				_r = areas[j].right;
			} else
				_r = Math.max(_r, areas[j].right);
		marksList.add(new Mark(true, _l - 1, lastT));
		marksList.add(new Mark(false, _r, lastT));
		
		
		Mark[] marks = marksList.toArray(formatMark);
		Arrays.sort(marks, new Comparator<Mark>() {
			@Override
			public int compare(Mark arg0, Mark arg1) {
				return arg0.position - arg1.position;
			}
		});

		BigInteger ans = BigInteger.ZERO;
		int j = 0;
		Treap spends = new Treap();
		TreeMap<Integer, Integer> times = new TreeMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			while (j < marks.length && marks[j].position <= i) {
				if (marks[j].insert) {
					Integer pro = times.ceilingKey(marks[j].time + 1);
					Integer pre = times.floorKey(marks[j].time - 1);
					times.put(marks[j].time, 0);
					int preTime = 0;
					if (pre != null)
						preTime = pre;
					if (pro != null) {
						spends.delete(pro - preTime);
						spends.insert(pro - marks[j].time);
					}
					spends.insert(marks[j].time - preTime);
				} else {
					Integer pro = times.ceilingKey(marks[j].time + 1);
					Integer pre = times.floorKey(marks[j].time - 1);
					times.remove(marks[j].time);
					int preTime = 0;
					if (pre != null)
						preTime = pre;
					if (pro != null) {
						spends.delete(pro - marks[j].time);
						spends.insert(pro - preTime);
					}
					spends.delete(marks[j].time - preTime);
				}
				j++;
			}

			if (times.size() <= 0)
				continue;
			
			if (maxPower[i].equals(BigInteger.ZERO))
				continue;
			
			if (rapid[i].equals(BigInteger.ZERO)) {
				ans = ans.add(startPower[i]);
				continue;
			}
			
			int mid = maxPower[i].add(rapid[i]).subtract(BigInteger.ONE).divide(rapid[i]).intValue();
			int before = spends.sumLessThan(mid);
			int after = spends.countMoreThan(mid - 1);
			int firstTime = times.firstKey();
			
			ans = ans.add(BigInteger.valueOf(after).multiply(maxPower[i]));
			if (firstTime >= mid) {
//				ans += after * maxPower[i] + before * rapid[i];
				ans = ans.add(BigInteger.valueOf(before).multiply(rapid[i]));
			} else {
//				ans += after * maxPower[i] + (before - firstTime) * rapid[i] + Math.min(maxPower[i], rapid[i] * firstTime + startPower[i]);
				ans = ans.add(BigInteger.valueOf(before - firstTime).multiply(rapid[i]));
				BigInteger tmp = rapid[i].multiply(BigInteger.valueOf(firstTime)).add(startPower[i]);
				if (tmp.compareTo(maxPower[i]) > 0)
					ans = ans.add(maxPower[i]);
				else
					ans = ans.add(tmp);
			}
		}
		
		System.out.println(ans);
	}

}
